(* -- Liste de depart -- *)

let l = [("don",435.);("Nut",75.);("Toto",42.)];;

(* -------------- *)

let compare a b =
 
    if a > b 
     then
      1

    else if a < b 
     then
    (-1)

    else 
      0 ;;

compare 2 1;;

(* -------------- *)

let rec find n list =

 match list with

     [] -> failwith "client encore inconnu"
    |(a,b)::list -> if a = n then b else find n list ;;

find "Toto" l;;

(* -------------- *)

let rec add (nom1,chiffre1) list = match list with
  [] -> (nom1,chiffre1)::[]
  |(nom,chiffre)::list when String.lowercase (nom1) < String.lowercase (nom) -> (nom1,chiffre1)::(nom,chiffre)::list
  |(nom,chiffre)::list when String.lowercase (nom) = String.lowercase (nom1) -> (nom,chiffre)::list
  |(nom,chiffre)::list -> (nom,chiffre)::(add (nom1,chiffre1) list);;

add ("znerf",49.) l;;

(* -------------- *)

let rec delete nom list =

  match list with
   [] -> []
  |(c,d)::list -> 
    if c = nom then
      list
    else (c,d)::(delete nom list) ;;

delete ("Nut") l;;

(* -------------- *)

let rec update nom chiffre list =

  match list with
   [] -> []
  |(c,d)::list -> 
    if c = nom then
      (nom,chiffre)::list
    else (c,d)::(update nom chiffre list) ;;

update "Nut" 57. l;;

(* -------------- *)

let rec name nom nom1 list =

  match list with
   [] -> []
  |(c,d)::list -> 
    if c = nom then
      (nom1,d)::list
    else (c,d)::(name nom nom1 list) ;;

name "Nut" "Nuttttte" l;;

(* -------------- *)
